/*
 * Created on 27 fevr. 2004
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package communication;

import java.io.Serializable;

import kernel.Simulator;
import objects.Station;

/**
 * @author Equipe SimPack 2004
 * An action is used by a protocol to explain what the stations are supposed to do 
 */
public abstract class Action implements Serializable {
	protected Station actor;
	protected double startTime;
	protected double duration;
	protected Simulator simulator;
	protected boolean properlyEnded;
	
	/**
	 * constructor of an Action
	 * @param s the station involved
	 * @param start the date when the Action starts
	 * @param dur the lenght time of the Action
	 */
	
	public Action(Station s, double start, double dur, Simulator sim){
		actor=s;
		startTime=start;
		duration=dur;
		simulator= sim;
	}
	
	/**
	 * fonction that return the Station Actor of this Action
	 * @return Station
	 */
	public Station getActor(){
		return actor;
	}
	
	/**
	 * @return wether the action has been properly ended 
	 */
	public boolean getProperlyEnded(){
		return properlyEnded;
	}
	
	
	/**
	 * @return start time of this action
	 */
	public double getStartTime(){
		return startTime;
	}
	/**
	 * 
	 * @return the duration of an Action
	 */
	public double getDuration(){
		return duration;
	}
	
	
	/**
	 * 
	 * @return wether the action has been ended since last time
	 */
	public boolean ended(){
		properlyEnded=(startTime+duration)<=simulator.getTime();
			return 	properlyEnded;
	}

	
	/**
	 * Update all values that are linked with the execution of an action during the current communication
	 * 
	 */
	public abstract void executeAction() ;
	
	/**
	 * @return a text description of the action
	 */
	public abstract String toString();
	
	
	
	
/**
 * function called by the CommunicationMAnager when a Action was bad finished ( action not finished and new action create) in order to let the kernel in good state
 * or called by this action by the method ended when the action is terminated .
 * This function is the opposite of executeAction
 */
	public abstract void makeProperlyEnd();
	
	/**
	 * @return
	 */
	public Simulator getSimulator() {
		return simulator;
	}

	/**
	 * @param station
	 */
	public void setActor(Station station) {
		actor = station;
	}

	/**
	 * @param d
	 */
	public void setDuration(double d) {
		duration = d;
	}

	/**
	 * @param b
	 */
	public void setProperlyEnded(boolean b) {
		properlyEnded = b;
	}

	/**
	 * @param simulator
	 */
	public void setSimulator(Simulator simulator) {
		this.simulator = simulator;
	}

	/**
	 * @param d
	 */
	public void setStartTime(double d) {
		startTime = d;
	}

}
